package com.zline.foodraise.view;

import android.content.Context;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.zline.foodraise.R;
import com.zline.foodraise.entity.TemplateBean;
import com.zline.foodraise.listener.RecyclerItemClicked;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/9/16.
 * 模板处理中的模板缩略图Item
 */
@EViewGroup(R.layout.template_process_thumb_list_item)
public class TemplateProcessThumbItem extends RelativeLayout {
    private static final String LOG_TAG = TemplateProcessThumbItem.class.getSimpleName();
    @ViewById(R.id.thumbnail_iv)
    ImageView thumb_iv;
    @ViewById(R.id.thumbnail_stroke_rl)
    RelativeLayout stroke_rl;
    int position;
    RecyclerItemClicked itemClicked;
    ImageLoader imageLoader;

    public TemplateProcessThumbItem(Context context) {
        super(context);
    }

    public void bind(int position,long templateId,TemplateBean bean,DisplayImageOptions options){
        this.position=position;
        if(bean!=null){
            String thumbpath= bean.getThumbnails();
            long mtemplateId=bean.getTemplateId();
            //选中状态有红边框
            if(mtemplateId==templateId){
                stroke_rl.setBackgroundResource(R.drawable.thumb_item_iv_bg);
            }else{
                stroke_rl.setBackground(null);
            }
            imageLoader = ImageLoader.getInstance();
            imageLoader.displayImage(thumbpath, thumb_iv, options);
        }
    }

    public void setRecycleItemClickListener(RecyclerItemClicked itemClickListener){
        this.itemClicked=itemClickListener;
    }

    @Click(R.id.thumbnail_stroke_rl)
    void onClick(){
        itemClicked.onRecyclerItemClicked(position);
    }
}
